package com.atguigu.lease.web.app;

import com.atguigu.lease.model.enums.LeaseStatus;
import org.springframework.core.convert.converter.Converter;

import java.util.Arrays;

public class StringToLeaseStatusConverter implements Converter<String, LeaseStatus> {
    @Override
    public LeaseStatus convert(String source) {
        int code = Integer.parseInt(source);
        return Arrays.stream(LeaseStatus.values())
                .filter(e -> e.getCode() == code)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效状态码: " + code));
    }
}
